package fm.last.api
{
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    
    import fm.last.Agent;
    import fm.last.RestAPI;
    
    final public class TagAPI extends RestAPI
    {
        // those in comment are not implemented yet
        public static const TAG_GET_SIMILAR:String             = "tag.getSimilar";
        public static const TAG_GET_TOP_ALBUMS:String          = "tag.getTopAlbums";
        public static const TAG_GET_TOP_ARTISTS:String         = "tag.getTopArtists";
        public static const TAG_GET_TOP_TAGS:String            = "tag.getTopTags";
        public static const TAG_GET_TOP_TRACKS:String          = "tag.getTopTracks";
        public static const TAG_GET_WEEKLY_ARTIST_CHART:String = "tag.getWeeklyArtistChart";
        public static const TAG_GET_WEEKLY_CHART_LIST:String   = "tag.getWeeklyChartList";
        public static const TAG_SEARCH:String                  = "tag.search";
        
        public function TagAPI(agent:Agent)
        {
            super(agent);
        }

        /* ********************************************************************/
        
        
        /** tag.getSimilar */
        public function getSimilar(onComplete:Function, 
                                   onError:Function,
                                   tag:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = TagAPI.TAG_GET_SIMILAR;
            urlVars["tag"] = tag;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** tag.getTopAlbums */
        public function getTopAlbums(onComplete:Function, 
                                   onError:Function,
                                   tag:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = TagAPI.TAG_GET_TOP_ALBUMS;
            urlVars["tag"] = tag;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** tag.getTopArtists */
        public function getTopArtists(onComplete:Function, 
                                   onError:Function,
                                   tag:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = TagAPI.TAG_GET_TOP_ARTISTS;
            urlVars["tag"] = tag;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** tag.getTopTags */
        public function getTopTags(onComplete:Function, 
                                   onError:Function):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = TagAPI.TAG_GET_TOP_TAGS;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** tag.getTopTracks */
        public function getTopTracks(onComplete:Function, 
                                   onError:Function,
                                   tag:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = TagAPI.TAG_GET_TOP_TRACKS;
            urlVars["tag"] = tag;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        

        /** tag.getWeeklyArtistChart */
        public function getWeeklyArtistChart(onComplete:Function, 
                                             onError:Function,
                                             tag:String,
                                             from:String=null,
                                             to_:String=null,
                                             limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = TagAPI.TAG_GET_WEEKLY_ARTIST_CHART;
            urlVars["tag"] = tag;
            if (from!=null) urlVars["from"] = from;
            if (to_!=null) urlVars["to"] = to_;
            if (limit>0) urlVars["limit"] = limit;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** tag.getWeeklyChartList */
        public function getWeeklyChartList(onComplete:Function, 
                                             onError:Function,
                                             tag:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = TagAPI.TAG_GET_WEEKLY_CHART_LIST;
            urlVars["tag"] = tag;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        

        /** tag.search */
        public function search(onComplete:Function, 
                                             onError:Function,
                                             tag:String,
                                             page:int=-1,                                            
                                             limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = TagAPI.TAG_SEARCH;
            urlVars["tag"] = tag;
            if (page>0)  urlVars["page"] = page;
            if (limit>0) urlVars["limit"] = limit;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

    }
}